#include <stdio.h>

int main_30()
{
    int r,y,g,n,k,t,time=0;
    scanf("%d%d%d%d",&r,&y,&g,&n);
    while (n--)
    {
        scanf("%d%d",&k,&t);
        switch (k)
        {
        case 0://no
        case 1://red
            time+=t;
            break;
        case 2://yellow
            time+=t;
            time+=r;
            break;
        }

    }
    printf("%d\n",time);
	return 0;
}
